

/**********************


	reducedform.do
	REPLICATES REDUCED FORM RESULTS WITH SIMULATED DATA AND COMPARES THEM TO RESULTS WITH ORIGINAL DATA
			
	** Current directory use: set up local direcdtory as folder containing dta of both original and
		simulated data.
	
	OLD FORMAT:	
	Directory is ...zambiatrees/
	* Inputs: "/zambiatrees/estimation/program/Estimation.dta" and "/zambiatrees/Estimation/Testing/zambia_simht.dta"		
	* Outputs: tables and figures in "...Data/output/..."
	
	Outline:	

	0) Setup
	1) miscellaneous cleaning, variable construction
	2) actual data: reduced form regs and results
	3) simulated data prep
	4) simulated data data: reduced form regs and results
	5) tree survival histogram
				
**********************/


**********************
** (0) SETUP 
**********************

clear all 
mata: mata clear
cap log close
set more off
set trace off
set linesize 140
set memory 200m
set matsize 1000
set maxvar 10000
*set scheme s2mono
set scheme s2color
set seed 123456789
timer clear

** Excel outfile name **
local outfilename reducedform_results
local outtype excel

**********************
** (1) CLEANING AND CONSISTENCY WITH SIMULATED DATA
**********************

*cd "$d1"
use "Matlab_2014_12_cluster.dta", clear

forvalues i=1/51 {
 gen altgroup`i'=igroup`i'*(`i'-1)
}

egen tree_survive=rowtotal(altgroup1-altgroup51)

g zero=tree_survive==0 & takeup==1

**********************
** (2)  REDUCED FORM RESULTS
**********************

*cd "$d2"
reg takeup a, cluster(group)
outreg2 a using `outfilename', `outtype' paren(se) bdec(3) replace nocons
reg comply a if takeup==1, cluster(group)
outreg2 a using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg tree_survive a if takeup==1 & tree_survive>0, cluster(group)
outreg2 a using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg zero a if takeup==1, cluster(group)
outreg2 a using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg takeup r if treat==0, cluster(group)
outreg2 r using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg comply r if takeup==1, cluster(group)
outreg2 r using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg tree_survive r if takeup==1 & tree_survive>0, cluster(group)
outreg2 r using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg zero r if takeup==1, cluster(group)
outreg2 r using `outfilename', `outtype' paren(se) bdec(3) append nocons


**********************
** (3) LABELING SIMULATED DATA
**********************

use "zambia_simdata.dta", clear

/* RENAMING VARIABLES */
rename col1 a
rename col2 r
rename col3 takeup
rename col4 tree_survive
rename col5 Prof0
rename col6 Prof1
rename col7 tg
rename col8 mongr
rename col9 group

replace tree_survive=0 if takeup==0

/* GENERATE COMPLY AND ZERO VARIABLES*/gen comply=0
replace comply=1 if tree_survive>=35
g zero=tree_survive==0 & takeup==1

**********************
** (4)  REDUCED FORM RESULTS FROM SIMULATION
**********************

*cd "$d2"
reg takeup a, cluster(group)
outreg2 a using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg comply a if takeup==1, cluster(group)
outreg2 a using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg tree_survive a if takeup==1 & tree_survive>0, cluster(group)
outreg2 a using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg zero a if takeup==1, cluster(group)
outreg2 a using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg takeup r if tg==0, cluster(group)
outreg2 r using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg comply r if takeup==1, cluster(group)
outreg2 r using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg tree_survive r if takeup==1 & tree_survive>0, cluster(group)
outreg2 r using `outfilename', `outtype' paren(se) bdec(3) append nocons
reg zero r if takeup==1, cluster(group)
outreg2 r using `outfilename', `outtype' paren(se) bdec(3) append nocons

**********************
** (5)  Tree Survival histogram
**********************

hist tree_survive, bin(51)
graph export sim_histogram.pdf










